package imageProcessing.filter;

import imageProcessing.Duplicator;
import imageProcessing.ImageEvent;
import imageProcessing.ImageListener;

import java.util.ArrayList;

import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;

public class NotFilter implements ImageListener{

	private ArrayList<ImageListener> listeners;	
	private PlanarImage m_image;
	
	public NotFilter(){
		listeners = new ArrayList<ImageListener>();
		m_image = null;
	}

	public void notifyListeners() {
			ImageEvent ie  = new ImageEvent(this, m_image);
			ArrayList<ImageListener> copy = Duplicator.copyListeners(listeners);
			for (ImageListener listener : copy) {
				listener.imageChanged(ie);
			}
	}
		
	public void addImageListener(ImageListener imageListener){
		listeners.add(imageListener);
	}
	
	public void removeImageListener(ImageListener imageListener){
		listeners.remove(imageListener);
	}
	@Override
	public void imageChanged(ImageEvent ie) {
		PlanarImage img = ie.getImage();		
		// TODO: Add Filter-code here
		m_image =  JAI.create("invert", img);
		notifyListeners();
	}
		
}